package com.bjsxt.config.geetest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * description:
 * 极验配置文件自动装配配置类
 *
 * @author ALIENWARE <br />
 * @date 2021/9/5
 */
@Configuration
@EnableConfigurationProperties(GeetestProperties.class)
public class GeetestAutoConfiguration {
    /**
     * 极验相关配置文件 因为上面写了 EnableConfigurationProperties 注解所以这里不用谢 AutoWired 也能进行注入
     */
    private GeetestProperties geetestProperties;

    /**
     * 根据构造器进行注入配置文件
     *
     * @param geetestProperties 极验相关配置文件
     */
    @Autowired
    public GeetestAutoConfiguration(GeetestProperties geetestProperties) {
        this.geetestProperties = geetestProperties;
    }

    /**
     * 配置 GeetestLib 对象
     *
     * @return GeetestLib 对象
     */
    @Bean
    public GeetestLib geetestLib() {
        return new GeetestLib(geetestProperties.getGeetestId(), geetestProperties.getGeetestKey());
    }
}
